package base

import (
	"context"
	"rewords-server-2024/internal/consts"
	"rewords-server-2024/internal/model/entity"
	"rewords-server-2024/internal/model/input/query_in"
	"rewords-server-2024/internal/service"

	"github.com/gogf/gf/v2/errors/gerror"

	"rewords-server-2024/api/base/system"
)

func (c *ControllerSystem) SysUserInfo(ctx context.Context, req *system.SysUserInfoReq) (res *system.SysUserInfoRes, err error) {
	// 构建查询条件和 排序条件
	query, _, projection := query_in.BuildMongoQuery(req.Conditions, req.OrderFields, []string{"username", "email", "uid"})
	//query, _, projection := query_in.BuildMongoQuery(req.Conditions, req.OrderFields, []string{})
	var user entity.SysUser
	if err := service.Mgx().FindOneAndDecode(ctx, consts.CUser, query, projection, &user); err != nil {
		return nil, gerror.Wrap(err, "获取用户信息失败")
	}
	return &system.SysUserInfoRes{SysUser: user}, nil
}
